﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SWEN3Application.Classes;

namespace SWEN3Application
{
    public partial class Housekeeping : MasterForm
    {
        public Housekeeping()
        {
            InitializeComponent();
            ArrayList room = new ArrayList();
            room = HousekeepingDBManager.GetAllRooms();           
            foreach (housekeepingOscar h in room)
            {
                cbFindRoom.Items.Add(Convert.ToInt32(h.roomNo));
                CBUpdateHouseSche.Items.Add(Convert.ToInt32(h.roomNo)); 
            }

            
        }

        private void btnSearchUpdate_Click(object sender, EventArgs e)
        {
            if (CBUpdateHouseSche.Text != "")
            {
                housekeepingOscar h = HousekeepingDBManager.GetRoomByRoomNo(Convert.ToInt32(CBUpdateHouseSche.SelectedItem));
                panel2.Visible = true;
                tbxUpdateInCharge.Text = h.inCharge;
                tbxUpdateRoomStatus.Text = h.roomStatus;
                tbxUpdateRoomType.Text = h.roomType;
                dtpUpdateCleaningEndTime.Text = Convert.ToString(h.cleaningEndTime);
                dtpUpdateCleaningStartTime.Text = Convert.ToString(h.cleaningStartTime);
            }
            else
            {
                MessageBox.Show("Please choose a room");
            }
            
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (tbxUpdateInCharge.Text != "" && tbxUpdateRoomType.Text != "" && tbxUpdateRoomStatus.Text != "" && CBUpdateHouseSche.Text != "")
            {
                string inCharge = tbxUpdateInCharge.Text;
                DateTime cleaningEndTime = dtpUpdateCleaningEndTime.Value;
                string roomType = tbxUpdateRoomType.Text;
                string roomStatus = tbxUpdateRoomStatus.Text;
                DateTime cleaningStartTime = dtpUpdateCleaningStartTime.Value;
                int roomNo = Convert.ToInt32(CBUpdateHouseSche.SelectedItem);

                var housekeeping = new housekeepingOscar() { roomNo = roomNo, inCharge = inCharge, cleaningStartTime = cleaningStartTime, cleaningEndTime = cleaningEndTime, roomStatus = roomStatus, roomType = roomType };
                HousekeepingDBManager.UpdateHousekeeping(housekeeping);
                MessageBox.Show("Successfully Updated!");


                return;
            }
            else
            {
                MessageBox.Show("Please fill in all blanks!");
            }
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            int roomNum = Convert.ToInt32(cbFindRoom.SelectedItem);
            ArrayList room = new ArrayList();
            room = HousekeepingDBManager.GetAllRoomNo(roomNum);
            housekeepinggrid.DataSource = room;

        }

        private void Housekeeping_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'housekeepingOI.Housekeeping' table. You can move, or remove it, as needed.
            this.housekeepingTableAdapter.Fill(this.housekeepingOI.Housekeeping);

        }

        private void btnSearch_Click_1(object sender, EventArgs e)
        {

        }

        private void btnSearchHousekeeping_Click(object sender, EventArgs e)
        {
            int roomNum = Convert.ToInt32(cbFindRoom.SelectedItem);
            ArrayList housekeeping = new ArrayList();
            housekeeping = HousekeepingDBManager.GetAllRoomNo(roomNum);
            housekeepinggrid.DataSource = housekeeping;
        }

        private void btnSearchByStatus_Click(object sender, EventArgs e)
        {
            string status = Convert.ToString(cbShowRooms.SelectedItem);
            ArrayList r = new ArrayList();
            r = HousekeepingDBManager.GetAllStatus(status);
            housekeepinggrid.DataSource = r; 
        }

        private void btnViewAllRooms_Click(object sender, EventArgs e)
        {
            ArrayList viewroom = new ArrayList();
            viewroom = HousekeepingDBManager.GetAllRoom();
            housekeepinggrid.DataSource = viewroom;
        }

        
    }
}
